package com.shuqi.common.utils;

import com.shuqi.common.RedDotProvider;
import com.shuqi.database.dao.impl.VersionShowDao.VersionShowEnum;
import com.shuqi.model.BookContentSettings;

import android.content.Context;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.text.TextUtils;

/**
 * SharedPreference工具类, 根据需要创建属于自己的SharedPreference，set()，get(); <BR>
 * <b> <BR>
 * SharedPreferences 文件名以及文件中的字段名 <BR>
 * 文件名格式：SP_NAME_**** <BR>
 * 文件中字段key值格式：SP_****_INT(存储字段类型)_功能名 <BR>
 * </b>
 * 
 * @remark 根据需要可以定义各自的remove()方法
 * @author Jianda.Yang
 * @date 2013-12-13 下午2:19:08
 * @version 1.0
 */
public class SharedPreferenceUtil {
    private static SharedPreferenceUtil mSharedPreferenceUtil = null;

    /** SharedPreferences 文件名 config 存储软件设置相关的参数 */
    public static final String SP_NAME_CONFIG = "config";

    /** SharedPreferences config 中的字段名：key 通知栏更新功能开关 boolean */
    public static final String SP_CONFIG_BOOLEAN_NOTIFICATIONREMIND = "notificationRemind";
    /** SharedPreferences config 中的字段名：key 检查书签更新成功的时间 long */
    public static final String SP_CONFIG_LONG_LASTUPDATEBOOKMARKTIME = "lastUpdateBookMarkTime";
    /** SharedPreferences config 中的字段名：key 打开软件打开书架 boolean */
    public static final String SP_CONFIG_BOOLEAN_OPENSHELF = "isStartOpenShelf";

    /** SharedPreferences config 中的字段名：key 是否创建了快捷方式 boolean */
    public static final String SP_CONFIG_BOOLEAN_CREATEDSHORCUT = "isCreatedShorCut";

    /** SharedPreferences 文件名：联网服务器域名相关 */
    public static final String SP_NAME_SERVERS = "serverlist";

    /** SharedPreferences 文件名：网页域名、网址相关 */
    public static final String SP_NAME_WEBURLS = "weburls";

    /** SharedPreferences 文件名：静态不需要重试的域名：1：广告CDN域名 */
    public static final String SP_NAME_STATICDOMAINS = "staticDomains";

    /** SharedPreferences 文件名：推广墙列表 */
    public static final String SP_NAME_OFFERWALL = "offerwall";

    /** SharedPreferences中保存图片路径的key */
    public final static String PicPathKey = "loadingPic";

    /** SharedPreferences 文件名：软件升级版本号保存相关 */
    public static final String SP_NAME_TIPS = "tips";
    /** SharedPreferences tips 中的字段名：key ：当前版本号 String */
    public static final String SP_TIPS_STRING_VERSIONCHANGE = "versionchange";
    /** SharedPreferences tips 中的字段名：key ：上一次版本号String */
    public static final String SP_TIPS_STRING_PREVERSION = "preversion";
    /** SharedPreferences tips 中的字段名：key ：本版本是否显示过新手引导 boolean */
    public static final String SP_TIPS_BOOLEAN_SHOWEDNEWVERSIONTIP = "showedNewVersionTip";

    /** SharedPreferences download_hint 中的字段名：key ：是否显示webkit中离线下载提示boolean */
    public static final String SP_NAME_DOWNLOAD_HINT = "download_hint";

    private SharedPreferenceUtil() {

    }

    public static SharedPreferenceUtil getInstanceSharedPreferenceUtil() {
        if (mSharedPreferenceUtil == null) {
            synchronized (SharedPreferenceUtil.class) {
                if (mSharedPreferenceUtil == null) {
                    mSharedPreferenceUtil = new SharedPreferenceUtil();
                }
            }
        }
        return mSharedPreferenceUtil;
    }

    /** 文件编码XML */
    private static final String SP_NAME_ENCODE_XML = "txtFileEncode";

    /**
     * 保存文件编码
     * 
     * @param contextk
     * @param filePathkey
     * @param valEncode
     */
    public static void setFileEncode(Context context, String filePathkey, String valEncode) {
        SharedPreferences settings =
                context.getSharedPreferences(SP_NAME_ENCODE_XML, Context.MODE_PRIVATE);
        settings.edit().putString(filePathkey, valEncode).commit();
    }

    /**
     * 获取文件编码
     * 
     * @param context
     * @param filePathkey
     * @return
     */
    public static String getFileEncode(Context context, String filePathkey) {
        SharedPreferences settings =
                context.getSharedPreferences(SP_NAME_ENCODE_XML, Context.MODE_PRIVATE);
        return settings.getString(filePathkey, null);
    }

    /** 文件自动断章XML */
    private static final String SP_NAME_CATALOGTOOL_XML = "catalogTool";

    /**
     * 保存自动断章标记
     * 
     * @param context
     * @param filePathkey
     * @param isCatalog
     */
    public static void setFileCatalogTool(Context context, String filePathkey, boolean isCatalog,
            boolean catalotFlag) {
        SharedPreferences settings =
                context.getSharedPreferences(SP_NAME_CATALOGTOOL_XML, Context.MODE_PRIVATE);
        settings.edit().putBoolean(filePathkey, isCatalog)
                .putBoolean(filePathkey + "_flag", catalotFlag).commit();
    }

    /**
     * 获取文件自动断章标记
     * 
     * @param context
     * @param filePathkey
     * @return
     */
    public static boolean getFileCatalogTool(Context context, String filePathkey) {
        SharedPreferences settings =
                context.getSharedPreferences(SP_NAME_CATALOGTOOL_XML, Context.MODE_PRIVATE);
        // Log4an.i("TxtTool",
        // "filePath=" + filePathkey + "\n,是否自动断章=" + settings.getBoolean(filePathkey, false));
        return settings.getBoolean(filePathkey, false);
    }

    /**
     * 获取文件目录某章节是否过大的标记
     * 
     * @remark 7.3.8
     * @param context
     * @param filePathkey
     * @return
     */
    public static boolean getFileCatalogFlag(Context context, String filePathkey) {
        SharedPreferences settings =
                context.getSharedPreferences(SP_NAME_CATALOGTOOL_XML, Context.MODE_PRIVATE);
        Log4an.i(
                "TxtTool",
                "filePath=" + filePathkey + "_flag" + "\n,断章读取数据标识="
                        + settings.getBoolean(filePathkey + "_flag", false));
        return settings.getBoolean(filePathkey + "_flag", false);
    }


    /** 设置横竖屏 */
    private static final String SP_SCREEN_PORTRAIT = "screenOrientation_portrait";
    /** 默认竖屏 */
    private static final boolean DEFAULT_SCREEN_PORTRAIT = true;
    /** 阅读页设置相关参数 */
    private static final String SP_SP_NAME_SETTING = "booksettings";
    /** 设置全屏 */
    private static final String SP_SETTING_IS_FULL_SCREEN = "isfullscreen";
    /** 音量翻页键 */
    private static final String SP_SETTING_IS_VOLUME_ENABLED = "isvolumeenabled";
    /** 夜间模式 */
    private static final String SP_SETTING_IS_NIGHT_MODE = "isnightmode";
    /** 点击两侧翻页模式 */
    private static final String SP_SETTING_IS_CLICKSIDE_TURNPAGEMODE = "clickSideturnpage";
    /** 夜间模式不再提醒 */
    private static final String SP_SETTING_NIGHT_MODE_NOWARN = "nightmodenowarn";
    /** 阅读页屏幕常亮时间 */
    private static final String SP_SETTING_KEEP_SCREEN_TIME = "keepscreentime";
    /** 主题模式 */
    private static final String SP_SETTING_THEME = "ptheme";
    /** 上次的主题 */
    private static final String SP_SETTING_LAST_THEME = "pthemelast";
    /** 阅读页帮助引导图 */
    private static final String SP_SETTING_HELP_SHOW = "helpshow";
    /** 屏幕亮度 */
    private static final String SP_SETTING_SCREEN_LIGHT = "screenlight";
    /** 系统按钮是否被点击 */
    private static final String SP_SETTING_SCREEN_SYSTEM_BUTTON = "clickSysbtn";
    /** 阅读页翻页模式 */
    private static final String SP_SETTING_PAGE_TURN_MODE = "pageturnmode";
    /** 默认行间距 (此值改变时也要重新resolve，以便重新计算少于一屏的章节) */
    // private static final int DEFAULT_LINESPACE = 30;
    /** 默认全屏 */
    private static final boolean DEFAULT_FULLSCREEN = true;
    /** 音量键翻页默认值 */
    private static final boolean DEFAULT_VOLUME_ENABLED = true;
    /** 默认是否是夜间模式 */
    private static boolean DEFAULT_IS_NIGHTMODE = false;
    /** 点击页面两侧翻页默认值 */
    private static final boolean DEFAULT_SIDE_ENABLED = false;
    /** 默认夜间模式对话框不再提示状态 */
    private static final boolean DEFAULT_NIGHT_MODE_NOWARN = false;
    /** 默认阅读页屏幕亮时间 */
    private static final int DEFAULT_KEEP_SCREEN_TIME = 5 * 60 * 1000;
    /** 默认主题模式 */
    private static final int DEFAULT_THEME = 1;
    /** 默认屏幕亮度 */
    private static final int DEFAULT_LIGHT = 60;
    /** 阅读页默认翻页模式 */
    private static final int DEFAULT_PAGE_TURN_MODE = 1;

    private static SharedPreferences mSharedPreferences;

    // ============
    /** 字档 */
    private static final String SP_SETTING_SIZEPOSITION = "sizeposition";
    /** 风格 */
    private static final String SP_SETTING_STYLE = "style";
    /** 设置正文页字体大小 */
    private static final String SP_SETTING_TEXTSIZE = "textsize";
    /** 设置正文页标题字体大小 */
    private static final String SP_SETTING_TITLE_TEXTSIZE = "texttitlesize";
    /** 标题与正文间距 */
    private static final String SP_SETTING_TITLE_SPACE = "texttitlespace";
    /** 设置行间距 */
    private static final String SP_SETTING_LINESPACE = "linespace";
    /** 设置段间距 */
    private static final String SP_SETTING_PARAGRAPHSPACE = "paragraphspace";

    // ============

    /**
     * 获取SharedPreferences对象
     * 
     * @param context
     * @return
     */
    public SharedPreferences getShaPreferencesInstance(Context context) {
        if (mSharedPreferences == null) {
            mSharedPreferences =
                    context.getSharedPreferences(SP_SP_NAME_SETTING, Context.MODE_PRIVATE);
        }
        return mSharedPreferences;
    }

    // =========================================================================================

    /**
     * 获取字档
     */
    public int getSizePosition() {
        return mSharedPreferences.getInt(SP_SETTING_SIZEPOSITION, 3);
    }

    /**
     * 保存字档
     */
    public void saveSizePosition(int position) {
        saveIntAttribute(SP_SETTING_SIZEPOSITION, position);
    }

    /**
     * 获取风格
     */
    public int getStyle() {
        return mSharedPreferences.getInt(SP_SETTING_STYLE, 0);
    }

    /**
     * 保存风格
     */
    public void saveStyle(int style) {
        saveIntAttribute(SP_SETTING_STYLE, style);
    }

    /**
     * 正文页字体大小
     */
    public void saveBookContentFontSize(int size) {
        saveIntAttribute(SP_SETTING_TEXTSIZE, size);
    }

    /**
     * 获取正文页字体大小
     */
    public int getBookContentFontSize() {
        return mSharedPreferences.getInt(SP_SETTING_TEXTSIZE,
                BookContentSettings.BOOKCONTENT_DEFAULT_TEXT_SIZE);
    }

    /**
     * 保存正文页标题字体大小
     */
    public void saveBookContentTitleFontSize(int size) {
        saveIntAttribute(SP_SETTING_TITLE_TEXTSIZE, size);
    }

    /**
     * 获取正文页标题字体大小
     */
    public int getBookContentTitleFontSize() {
        return mSharedPreferences.getInt(SP_SETTING_TITLE_TEXTSIZE,
                BookContentSettings.TITLE_DEFAULT_TEXT_SIZE);
    }

    /**
     * 获取标题与正文间距
     */
    public int getTitleSpace() {
        return mSharedPreferences.getInt(SP_SETTING_TITLE_SPACE,
                BookContentSettings.TITLE_DEFAULT_SPACE);
    }

    /**
     * 保存标题与正文间距
     */
    public void saveTitleSpace(int size) {
        saveIntAttribute(SP_SETTING_TITLE_SPACE, size);
    }

    /**
     * 保存行间距
     */
    public void saveBookContentLineSpace(int size) {
        saveIntAttribute(SP_SETTING_LINESPACE, size);
    }

    /**
     * 获取行间距
     */
    public int getBookContentLineSpace() {
        return mSharedPreferences.getInt(SP_SETTING_LINESPACE,
                BookContentSettings.LINE_DEFAULT_SPACE);
    }

    /**
     * 获取段间距
     */
    public int getBookContentParagraphSpace() {
        return mSharedPreferences.getInt(SP_SETTING_PARAGRAPHSPACE,
                BookContentSettings.PARAGRAPH_DEFAULT_SPACE);
    }

    /**
     * 保存段间距
     */
    public void saveBookContentParagraphSpace(int size) {
        saveIntAttribute(SP_SETTING_PARAGRAPHSPACE, size);
    }


    // ====================================================================================


    /**
     * 保存阅读页翻页模式
     * 
     * @param pageTurnMode
     */
    public void saveBookContentPageTurnMode(int pageTurnMode) {
        saveIntAttribute(SP_SETTING_PAGE_TURN_MODE, pageTurnMode);
    }

    /**
     * 获取阅读页翻页模式
     * 
     * @return
     */
    public int getBookContentPageTurnMode() {
        return mSharedPreferences.getInt(SP_SETTING_PAGE_TURN_MODE, DEFAULT_PAGE_TURN_MODE);
    }

    /**
     * 保存主题模式
     * 
     * @param theme
     */
    public void saveBookContentTheme(int theme) {
        saveIntAttribute(SP_SETTING_THEME, theme);
    }

    /**
     * 获取主题模式
     * 
     * @return
     */
    public int getBookContentTheme() {
        return mSharedPreferences.getInt(SP_SETTING_THEME, DEFAULT_THEME);
    }

    /**
     * 保存上次主题模式
     * 
     * @param theme
     */
    public void saveBookContentLastTheme(int theme) {
        saveIntAttribute(SP_SETTING_LAST_THEME, theme);
    }

    /**
     * 获取上次主题模式
     * 
     * @return
     */
    public int getBookContentLastTheme() {
        return mSharedPreferences.getInt(SP_SETTING_LAST_THEME, DEFAULT_THEME);
    }

    /**
     * 保存系统按钮点击状态
     * 
     * @param isClickSystemButton
     */
    public void saveBookContentSystemButton(boolean isClickSystemButton) {
        saveBooleanAttribute(SP_SETTING_SCREEN_SYSTEM_BUTTON, isClickSystemButton);
    }

    /**
     * 获取系统按钮点击状态
     * 
     * @return
     */
    public boolean getBookContentSystemButton() {
        return mSharedPreferences.getBoolean(SP_SETTING_SCREEN_SYSTEM_BUTTON, true);
    }

    /**
     * 系统亮度
     * 
     * @param light
     */
    public void saveBookContentScreenLight(int light) {
        saveIntAttribute(SP_SETTING_SCREEN_LIGHT, light);
    }


    /**
     * 获取屏幕亮度
     * 
     * @return
     */
    public int getBookContentLight() {
        return mSharedPreferences.getInt(SP_SETTING_SCREEN_LIGHT, DEFAULT_LIGHT);
    }

    /**
     * 阅读页帮助引导图
     * 
     * @param isShow
     */
    public void saveBookContentHelpImageState(boolean isShow) {
        saveBooleanAttribute(SP_SETTING_HELP_SHOW, isShow);
    }

    /**
     * 获取阅读页帮助引导图状态
     * 
     * @return
     */
    public boolean getBookContentHelpImageState() {
        return mSharedPreferences.getBoolean(SP_SETTING_HELP_SHOW, false);
    }


    /**
     * 保存是否是全屏属性
     * 
     * @param isFullScreen
     */
    public void saveBookContentFullScreen(boolean isFullScreen) {
        saveBooleanAttribute(SP_SETTING_IS_FULL_SCREEN, isFullScreen);
    }

    /**
     * 获取是否全屏
     * 
     * @return
     */
    public boolean getBookContentFullScreen() {
        return mSharedPreferences.getBoolean(SP_SETTING_IS_FULL_SCREEN, DEFAULT_FULLSCREEN);
    }

    /**
     * 保存是否是竖屏属性
     * 
     * @param isFullScreen
     */
    public void saveBookContentPortraitScreen(boolean isFullScreen) {
        saveBooleanAttribute(SP_SCREEN_PORTRAIT, isFullScreen);
    }

    /**
     * 获取是否竖屏
     * 
     * @return
     */
    public boolean getBookContentPortraitScreen() {
        return mSharedPreferences.getBoolean(SP_SCREEN_PORTRAIT, DEFAULT_SCREEN_PORTRAIT);
    }

    /**
     * 保存音量键翻页状态
     * 
     * @param isVolumeEnabled
     */
    public void saveBookContentVolumeEnabled(boolean isVolumeEnabled) {
        // Log4an.e("yjd", "[savie]isVolumeEnabled="+isVolumeEnabled);
        saveBooleanAttribute(SP_SETTING_IS_VOLUME_ENABLED, isVolumeEnabled);
    }

    /**
     * 获取音量键翻页状态
     * 
     * @return
     */
    public boolean getBookContentVolumeEnabled() {
        // Log4an.e("yjd",
        // "[get]isVolumeEnabled="+mSharedPreferences.getBoolean(SP_SETTING_IS_VOLUME_ENABLED,
        // DEFAULT_VOLUME_ENABLED));
        return mSharedPreferences.getBoolean(SP_SETTING_IS_VOLUME_ENABLED, DEFAULT_VOLUME_ENABLED);
    }

    /**
     * 保存夜间模式状态
     * 
     * @param isNightMode
     */
    public void saveBookContentNightMode(boolean isNightMode) {
        // Log4an.i("yjd", "保存夜间模式："+isNightMode);
        saveBooleanAttribute(SP_SETTING_IS_NIGHT_MODE, isNightMode);
    }

    /**
     * 获取夜间模式状态
     * 
     * @return
     */
    public boolean getBookContentNightMode() {
        // Log4an.i("yjd", "获取夜间模式："+mSharedPreferences.getBoolean(SP_SETTING_IS_NIGHT_MODE,
        // DEFAULT_IS_NIGHTMODE));
        return mSharedPreferences.getBoolean(SP_SETTING_IS_NIGHT_MODE, DEFAULT_IS_NIGHTMODE);
    }

    /**
     * 保存两侧翻页状态
     * 
     * @param isTurnPageMode
     */
    public void saveBookContentTurnpagemode(boolean isTurnPageMode) {
        saveBooleanAttribute(SP_SETTING_IS_CLICKSIDE_TURNPAGEMODE, isTurnPageMode);
    }

    /**
     * 获取两侧翻页状态
     * 
     * @return
     */
    public boolean getBookContentTurnPageMode() {
        return mSharedPreferences.getBoolean(SP_SETTING_IS_CLICKSIDE_TURNPAGEMODE,
                DEFAULT_SIDE_ENABLED);
    }

    /**
     * 保存夜间模式对话框不再提示状态
     * 
     * @param isNightModeNowarn
     */
    public void saveBookContentNightModeNowarn(boolean isNightModeNowarn) {
        saveBooleanAttribute(SP_SETTING_NIGHT_MODE_NOWARN, isNightModeNowarn);
    }

    /**
     * 获取夜间模式对话框不再提示状态
     * 
     * @return
     */
    public boolean getBookContentNightModeNowarn() {
        return mSharedPreferences.getBoolean(SP_SETTING_NIGHT_MODE_NOWARN,
                DEFAULT_NIGHT_MODE_NOWARN);
    }

    /**
     * 保存屏幕亮度时间
     * 
     * @param keepScreenTime
     */
    public void saveBookContentKeepScreenTime(int keepScreenTime) {
        saveIntAttribute(SP_SETTING_KEEP_SCREEN_TIME, keepScreenTime);
    }

    /**
     * 获取屏幕亮度时间
     * 
     * @return
     */
    public int getBookContentKeepScreenTime() {
        return mSharedPreferences.getInt(SP_SETTING_KEEP_SCREEN_TIME, DEFAULT_KEEP_SCREEN_TIME);
    }

    /**
     * 设置int类型属性
     * 
     * @param key
     * @param value
     */
    private void saveIntAttribute(String key, int value) {
        mSharedPreferences.edit().putInt(key, value).commit();
    }

    /**
     * 设置float类型属性
     * 
     * @param key
     * @param value
     */
    private void saveFloatAttribute(String key, float value) {
        mSharedPreferences.edit().putFloat(key, value).commit();
    }

    /**
     * 设置boolean类型属性
     * 
     * @param key
     * @param value
     */
    private void saveBooleanAttribute(String key, boolean value) {
        mSharedPreferences.edit().putBoolean(key, value).commit();
    }


    /**
     * 获取阅读页设置SharedPreferences对象
     * 
     * @param context
     * @return
     */
    public static SharedPreferences getSettingSP(Context context) {
        return context.getSharedPreferences(SP_SP_NAME_SETTING, Context.MODE_PRIVATE);
    }

    /**
     * 获取阅读页设置SP Editor对象
     * 
     * @param sp
     * @return
     */
    public static Editor getSettingEditor(SharedPreferences sp) {
        return sp.edit();
    }

    /**
     * 设置int类型属性
     * 
     * @remark 字体大小、行间距
     * @param editor
     * @param key
     * @param value
     */
    public static void setIntAttribute(Editor editor, String key, int value) {
        editor.putInt(key, value).commit();
    }

    /**
     * 设置boolean类型属性
     * 
     * @remark 是否全屏
     * @param editor
     * @param key
     * @param value
     */
    public static void setBooleanAttribute(Editor editor, String key, boolean value) {
        editor.putBoolean(key, value).commit();
    }

    /**
     * 获取int类型属性
     * 
     * @param sp
     * @param key
     * @param defValue
     * @return
     */
    public static int getIntAttribute(SharedPreferences sp, String key, int defValue) {
        return sp.getInt(key, defValue);
    }

    /**
     * 获取boolean类型属性
     * 
     * @remark 是否全屏
     * @param sp
     * @param key
     * @param defValue
     * @return
     */
    public static boolean getBooleanAttribute(SharedPreferences sp, String key, boolean defValue) {
        return sp.getBoolean(key, defValue);
    }

    /**
     * 移除指定key的数据
     * 
     * @param context
     * @param spName SharedPreferences名字
     * @param key 当key不空null时，删除指定key的数据；当key为null时，删除全部数据。(根据需要，谨慎传此参数)
     */
    public static void removeKeyFormSP(Context context, String spName, String key) {
        SharedPreferences sp = context.getSharedPreferences(spName, Context.MODE_PRIVATE);
        if (!TextUtils.isEmpty(key)) {
            sp.edit().remove(key).commit();
        } else {
            sp.edit().clear().commit();
        }
    }

    private static final String SP_NAME_FIRST_INLAYBOOK = "inlaybook";
    private static final String SP_KEY_FIRST_INLAYBOOK = "isFirstInlaybook";

    /**
     * 是否首次内置书籍
     * 
     * @param context
     * @param isChangeFirst,首次调用传false,当遇到切换账户等需要重新加载内置书籍时,传true
     * @return
     */
    public static boolean getInlayBookFirst(Context context) {
        SharedPreferences set =
                context.getSharedPreferences(SP_NAME_FIRST_INLAYBOOK, Context.MODE_PRIVATE);
        Boolean isFirst = set.getBoolean(SP_KEY_FIRST_INLAYBOOK, true);
        if (isFirst) {
            changeInlayBookFirst(context);
            return true;
        } else {
            return false;
        }
    }

    public static void changeInlayBookFirst(Context context) {
        SharedPreferences set =
                context.getSharedPreferences(SP_NAME_FIRST_INLAYBOOK, Context.MODE_PRIVATE);
        set.edit().putBoolean(SP_KEY_FIRST_INLAYBOOK, false).commit();
    }

    /**
     * 我的收藏列表
     */
    private static final String SP_NAME_MY_FAVORIT = "my_favorit";
    private static final String SP_KEY_MY_FAVORIT_IS_EDIT = "my_favorit_is_edit";


    public static boolean isMyFavoritEdit(Context context) {
        SharedPreferences set =
                context.getSharedPreferences(SP_NAME_MY_FAVORIT, Context.MODE_PRIVATE);
        Boolean isEdit = set.getBoolean(SP_KEY_MY_FAVORIT_IS_EDIT, false);

        return isEdit;
    }

    public static boolean setFavoritIsEdit(Context context, boolean isEdit) {
        SharedPreferences set =
                context.getSharedPreferences(SP_NAME_MY_FAVORIT, Context.MODE_PRIVATE);
        set.edit().putBoolean(SP_KEY_MY_FAVORIT_IS_EDIT, isEdit).commit();

        return false;
    }

    /**
     * 手动点更新红点提示
     */
    private static final String SP_NAME_SOFT_UPDATE = "soft_update";
    private static final String SP_NAME_SOFT_UPDATE_IS_SHOW = "soft_update_is_show";


    public static boolean isSoftUpdate(Context context) {
        SharedPreferences set =
                context.getSharedPreferences(SP_NAME_SOFT_UPDATE, Context.MODE_PRIVATE);
        Boolean isEdit = set.getBoolean(SP_NAME_SOFT_UPDATE_IS_SHOW, false);

        return isEdit;
    }

    public static boolean setSoftUpdate(Context context, boolean isShow) {
        SharedPreferences set =
                context.getSharedPreferences(SP_NAME_SOFT_UPDATE, Context.MODE_PRIVATE);
        set.edit().putBoolean(SP_NAME_SOFT_UPDATE_IS_SHOW, isShow).commit();

        if (!isShow) {
            RedDotProvider.getInstance().hideRedDot(VersionShowEnum.new_pull_version_red_dot);
        }

        return false;
    }

    /**
     * 推送版本提示
     */
    private static final String SP_NAME_VERSION_UPDATE = "version_update";
    private static final String SP_NAME_VERSION_UPDATE_PUSH_NO_PROMPT =
            "version_update_push_no_prompt";


    public static int getNoPromptPushVersion(Context context) {
        SharedPreferences set =
                context.getSharedPreferences(SP_NAME_VERSION_UPDATE, Context.MODE_PRIVATE);
        int noPromptVersion = set.getInt(SP_NAME_VERSION_UPDATE_PUSH_NO_PROMPT, Integer.MIN_VALUE);

        return noPromptVersion;
    }

    public static boolean setNoPromptPushVersion(Context context, int noPromptVersion) {
        SharedPreferences set =
                context.getSharedPreferences(SP_NAME_VERSION_UPDATE, Context.MODE_PRIVATE);
        set.edit().putInt(SP_NAME_VERSION_UPDATE_PUSH_NO_PROMPT, noPromptVersion).commit();

        return false;
    }

    /**
     * 删除wifi情况下缓存的 sharedpreference
     * 
     * @param bid
     * @param userId
     * @param sourceid
     */
    public static void deleteWifiTemp(Context context, String bid, String userId, String sourceid) {
        if (TextUtils.isEmpty(sourceid)) {
            sourceid = "";
        }
        SharedPreferences sp = context.getSharedPreferences("tempcatalog", context.MODE_PRIVATE);
        Editor editor = sp.edit();
        editor.remove(bid + "##" + userId + "##" + sourceid);
        editor.commit();
    }

}
